#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QBoxLayout>
#include <QDateTime>
#include <QGroupBox>
#include <QInputDialog>
#include <QLabel>
#include <QLineEdit>
#include <QMainWindow>
#include <QMessageBox>
#include <QPushButton>
#include <QScrollArea>
#include <QScrollBar>
#include <QSpacerItem>
#include <QTcpSocket>
#include <QVBoxLayout>
#include <QWidget>

#include "chatinfoframe.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow {
    Q_OBJECT

   public:
    explicit MainWindow(QTcpSocket* sock, QWidget* parent = 0);
    ~MainWindow();

   public slots:
    void handRead();
    void handClickChat();

   private slots:
    void on_buttonSendMessage_clicked();
    void on_actionAddFriend_triggered();
    void on_actionAbout_triggered();
    void getData(QString);
    void on_actionDeleteFriend_triggered();
    void on_actionRefreshOnlineState_triggered();
    void on_actionRefreshChat_triggered();

   private:
    Ui::MainWindow* ui;
    //按顺序保存聊天列表的指针
    std::vector<ChatInfoFrame*> chatList;
    //刷新聊天列表，用以更改排列
    void freshChatList();
    //新建一条信息的Frame
    QFrame* newMessageFrame(QString name, QString dateTime, QString message);
    //向信息框最底部插入一条信息并滚动到最底部
    void pushMessage(QFrame* messageFrame);
    //收到来自某用户的一条信息
    void receiveMessage(QString name, QString dateTime, QString message);

    //清空和显示当前聊天信息，当前聊天由presentFrame确定
    void clearPresentMessage();
    void showPresentMessage();

    //当前选中的聊天
    ChatInfoFrame* presentFrame = NULL;
    QTcpSocket* sock;

    //消息窗体顶端的弹簧
    QSpacerItem* chatMessageSpacer;

    int totalChatNumber = 0;
    int onlineChatNUmber = 0;
    QString username;
    QStringList recvStr1;
    QStringList recvStrList;
};

#endif  // MAINWINDOW_H
